package org.example.likou150.hash;

import java.util.Arrays;

public class CanConstruct {
    public static void main(String[] args) {
        CanConstruct canConstruct=new CanConstruct();
        System.out.println(canConstruct.canConstruct("aac", "aab"));
    }
    public boolean canConstruct(String ransomNote, String magazine) {
        char[] ransomNoteCharArray = ransomNote.toCharArray();
        char[] magazineCharArray = magazine.toCharArray();
        int[] bloom = new int[128];
        Arrays.fill(bloom, 0);
        for (char c : magazineCharArray) {
            bloom[c] = bloom[c] + 1;
        }
        for (char c : ransomNoteCharArray) {
            if (bloom[c] > 0) {
                bloom[c] = bloom[c] - 1;
            } else {
                return false;
            }
        }
        return true;
    }
}
